home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-05-13 | 49.1 KB | 1,653 lines |
- Newsgroups: comp.sources.misc
- From: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
- Subject: v29i097: zsh2.2 - The Z shell, Part01/17
- Message-ID: <csm-v29i097=zsh2.2.103215@sparky.IMD.Sterling.COM>
- X-Md4-Signature: 6c35d02622176e5f8e7212cd57a60307
- Date: Wed, 13 May 1992 15:52:04 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
- Posting-number: Volume 29, Issue 97
- Archive-name: zsh2.2/part01
- Environment: BSD
- Supersedes: zsh2.1: Volume 24, Issue 1-19
-
- #!/bin/sh
- # This is zsh2.2, a shell archive (produced by shar 3.49)
- # To extract the files from this archive, save it to a file, remove
- # everything above the "!/bin/sh" line above, and type "sh file_name".
- #
- # made 05/12/1992 04:14 UTC by pfalstad@phoenix
- # Source directory /n/homeserver/g/pfalstad
- #
- # existing files will NOT be overwritten unless -c is specified
- #
- # This is part 1 of a multipart archive
- # do not concatenate these parts, unpack them in order with /bin/sh
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 2684 -rw-r--r-- zsh2.2/FEATURES
- # 505 -rw-r--r-- zsh2.2/NOTES
- # 17490 -rw-r--r-- zsh2.2/README
- # 58603 -rw-r--r-- zsh2.2/doc/intro.txt
- # 247 -rw-r--r-- zsh2.2/dots/zlogin
- # 2291 -rw-r--r-- zsh2.2/dots/zshrc
- # 123 -rw-r--r-- zsh2.2/dots/zshenv
- # 104 -rwxr-xr-x zsh2.2/func/acx
- # 109 -rwxr-xr-x zsh2.2/func/cx
- # 97 -rwxr-xr-x zsh2.2/func/harden
- # 84 -rwxr-xr-x zsh2.2/func/mere
- # 412 -rwxr-xr-x zsh2.2/func/namedir
- # 194 -rwxr-xr-x zsh2.2/func/proto
- # 80 -rwxr-xr-x zsh2.2/func/randline
- # 29 -rwxr-xr-x zsh2.2/func/yp
- # 35 -rwxr-xr-x zsh2.2/func/yu
- # 112852 -rw-r--r-- zsh2.2/man/man1/zsh.1
- # 755 -rwxr-xr-x zsh2.2/scripts/aproto
- # 173 -rwxr-xr-x zsh2.2/scripts/fproto
- # 1137 -rw-r--r-- zsh2.2/scripts/ctoz
- # 2958 -rw-r--r-- zsh2.2/scripts/fooz
- # 3299 -rwxr-xr-x zsh2.2/scripts/c2z
- # 2736 -rwxr-xr-x zsh2.2/scripts/c2z.orig
- # 11626 -rwxr-xr-x zsh2.2/src/buildzsh
- # 61945 -rw-r--r-- zsh2.2/src/builtin.c
- # 4064 -rw-r--r-- zsh2.2/src/cond.c
- # 35818 -rw-r--r-- zsh2.2/src/exec.c
- # 1185 -rw-r--r-- zsh2.2/src/funcs.h
- # 24554 -rw-r--r-- zsh2.2/src/glob.c
- # 23511 -rw-r--r-- zsh2.2/src/hist.c
- # 11807 -rw-r--r-- zsh2.2/src/init.c
- # 16421 -rw-r--r-- zsh2.2/src/jobs.c
- # 15554 -rw-r--r-- zsh2.2/src/lex.c
- # 4752 -rw-r--r-- zsh2.2/src/loop.c
- # 10185 -rw-r--r-- zsh2.2/src/math.c
- # 4948 -rw-r--r-- zsh2.2/src/mem.c
- # 24577 -rw-r--r-- zsh2.2/src/params.c
- # 14912 -rw-r--r-- zsh2.2/src/subst.c
- # 6810 -rw-r--r-- zsh2.2/src/table.c
- # 8584 -rw-r--r-- zsh2.2/src/text.c
- # 32116 -rw-r--r-- zsh2.2/src/utils.c
- # 7149 -rw-r--r-- zsh2.2/src/watch.c
- # 8371 -rw-r--r-- zsh2.2/src/zle.h
- # 17212 -rw-r--r-- zsh2.2/src/zle_bindings.c
- # 14597 -rw-r--r-- zsh2.2/src/zle_main.c
- # 12058 -rw-r--r-- zsh2.2/src/zle_refresh.c
- # 4690 -rw-r--r-- zsh2.2/src/zle_utils.c
- # 31883 -rw-r--r-- zsh2.2/src/zsh.h
- # 4793 -rw-r--r-- zsh2.2/src/zle_vi.c
- # 1486 -rw-r--r-- zsh2.2/src/ztype.h
- # 26002 -rw-r--r-- zsh2.2/src/zle_tricky.c
- # 4239 -rw-r--r-- zsh2.2/src/builtin.pro
- # 235 -rw-r--r-- zsh2.2/src/cond.pro
- # 2306 -rw-r--r-- zsh2.2/src/exec.pro
- # 1511 -rw-r--r-- zsh2.2/src/glob.pro
- # 1989 -rw-r--r-- zsh2.2/src/hist.pro
- # 395 -rw-r--r-- zsh2.2/src/init.pro
- # 892 -rw-r--r-- zsh2.2/src/jobs.pro
- # 309 -rw-r--r-- zsh2.2/src/lex.pro
- # 206 -rw-r--r-- zsh2.2/src/loop.pro
- # 291 -rw-r--r-- zsh2.2/src/math.pro
- # 510 -rw-r--r-- zsh2.2/src/mem.pro
- # 3478 -rw-r--r-- zsh2.2/src/params.pro
- # 619 -rw-r--r-- zsh2.2/src/subst.pro
- # 941 -rw-r--r-- zsh2.2/src/table.pro
- # 371 -rw-r--r-- zsh2.2/src/text.pro
- # 3277 -rw-r--r-- zsh2.2/src/utils.pro
- # 371 -rw-r--r-- zsh2.2/src/watch.pro
- # 0 -rw-r--r-- zsh2.2/src/zle_bindings.pro
- # 686 -rw-r--r-- zsh2.2/src/zle_main.pro
- # 596 -rw-r--r-- zsh2.2/src/zle_refresh.pro
- # 761 -rw-r--r-- zsh2.2/src/zle_vi.pro
- # 1036 -rw-r--r-- zsh2.2/src/parse.pro
- # 1817 -rw-r--r-- zsh2.2/src/zle_tricky.pro
- # 18760 -rw-r--r-- zsh2.2/src/parse.c
- # 684 -rw-r--r-- zsh2.2/src/zle_utils.pro
- # 1429 -rw-r--r-- zsh2.2/src/signals.h.sample
- # 5181 -rw-r--r-- zsh2.2/src/zle_move.c
- # 14519 -rw-r--r-- zsh2.2/src/zle_misc.c
- # 6019 -rw-r--r-- zsh2.2/src/zle_word.c
- # 10080 -rw-r--r-- zsh2.2/src/zle_hist.c
- # 1119 -rw-r--r-- zsh2.2/src/zle_hist.pro
- # 1478 -rw-r--r-- zsh2.2/src/zle_misc.pro
- # 909 -rw-r--r-- zsh2.2/src/zle_move.pro
- # 733 -rw-r--r-- zsh2.2/src/zle_word.pro
- # 2607 -rw-r--r-- zsh2.2/src/config.h
- # 1322 -rw-r--r-- zsh2.2/src/signals.h
- # 921 -rw-r--r-- zsh2.2/src/Makefile
- #
- if test -r _shar_seq_.tmp; then
- echo 'Must unpack archives in sequence!'
- echo Please unpack part `cat _shar_seq_.tmp` next
- exit 1
- fi
- # ============= zsh2.2/FEATURES ==============
- if test ! -d 'zsh2.2'; then
- echo 'x - creating directory zsh2.2'
- mkdir 'zsh2.2'
- fi
- if test -f 'zsh2.2/FEATURES' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/FEATURES (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/FEATURES (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/FEATURES' &&
- Xvery close to ksh/sh grammar, with csh additions
- Xmost features of ksh, bash, and tcsh
- X75 builtins, 73 options, 144 key bindings
- Xshort for loops, ex: for i (*.c) echo $i
- Xselect
- Xshell functions
- Xconditional expressions (test builtin, [ ... ], and ksh-style [[ ... ]])
- Xglobal aliases (may be expanded anywhere on the line)
- Xdirectory stack access with =num
- Xprocess substitution (vi =(cmd) edits the output of cmd)
- Xgeneralized pipes (ls foo >>(cmd1) 2>>(cmd2) pipes stdout to cmd1
- X and stderr to cmd2)
- Xarithmetic expressions
- Xadvanced globbing:
- X ls **/file searches recursively for "file" in subdirectories
- X ls file<20-> matches file20, file30, file100, etc.
- X ls *.(c|pro) matches *.c and *.pro
- X ls *(R) matches only world-readable files
- X ls *.c~lex.c matches all .c files except lex.c
- Xnull command shorthands:
- X "< file" is same as "more <file"
- X "> file" is same as "cat >file"
- X ">> file" is same as "cat >>file"
- Xksh-style coprocesses
- Xautomatic file stream teeing (ls >foo >bar puts output in two places)
- Xchpwd() function run every time you change directory (useful for
- X updating the status line)
- Xjob control
- Xcsh-style history
- Xfull vi line editing, including "c2w" and "y$" and such things
- Xfull emacs line editing
- Xincremental history search
- Xmagic-space history
- Xspelling correction
- Xarray parameters
- X$HOSTTYPE, $LINENO, $RANDOM, $SECONDS, $cdpath, $COLUMNS, $fignore,
- X $HISTCHARS, $mailpath
- Xwith autocd option, typing a directory name by itself is the same as
- X typing "cd dirname"
- Xmenu completion: pressing TAB repeatedly cycles through the possible matches
- Xincremental path hashing
- Xautomatic process time reporting for commands that run over a certain limit
- Xfull tcsh-style prompt substitution
- Xutmp login/logout reporting
- Xwith histverify option, performing csh-style history expansions causes the
- X input line to be brought up for editing instead of being executed
- Xwith sunkeyboardhack option, accidently typed trailing ` characters
- X are removed from the input line (for those of you with Sun keyboards :-) )
- Xautoloaded functions (loaded from a file when they are first referenced)
- X"cd old new" replaces "old" with "new" in directory string
- Xgeneralized argument completion, including:
- X - command name completion
- X - filename and path completion
- X - hostname completion
- X - key binding completion
- X - option completion
- X - variable name completion
- X - user-specified keyword completion
- Xprompt on right side of screen
- Xdirectory stacks
- Xhistory datestamps and execution time records
- Xcommand scheduling (like at(1), but in the shell's context)
- Xtty mode freezing
- Xup to 9 startup files (but you only need 1 or 2)
- X8-bit clean
- Xwhich -a cmd lists all occurences of "cmd" in the path
- SHAR_EOF
- chmod 0644 zsh2.2/FEATURES ||
- echo 'restore of zsh2.2/FEATURES failed'
- Wc_c="`wc -c < 'zsh2.2/FEATURES'`"
- test 2684 -eq "$Wc_c" ||
- echo 'zsh2.2/FEATURES: original size 2684, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/NOTES ==============
- if test -f 'zsh2.2/NOTES' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/NOTES (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/NOTES (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/NOTES' &&
- XImportant notes:
- X
- X1. Stuff like "ls *.sdofij 2>/dev/null" to suppress error messages
- X produced by the shell don't work anymore. Filename generation is
- X done BEFORE redirection. To avoid the error message, use the
- X nonomatch option, or do "( ls *.sdofij ) 2>/dev/null".
- X
- X2. History substitution is no longer done inside startup files. If you
- X have sequences like \! or !" in your startup files, they will break.
- X (Especially !"). So check for those; remove the !", and change the
- X \! to !.
- SHAR_EOF
- chmod 0644 zsh2.2/NOTES ||
- echo 'restore of zsh2.2/NOTES failed'
- Wc_c="`wc -c < 'zsh2.2/NOTES'`"
- test 505 -eq "$Wc_c" ||
- echo 'zsh2.2/NOTES: original size 505, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/README ==============
- if test -f 'zsh2.2/README' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/README (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/README (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/README' &&
- XYou have permission to copy the zsh distribution in whole or in part
- Xas long as you don't try to make money off of it, or pretend that you
- Xwrote it.
- X
- XThis is zsh 2.2.0.
- X
- XTo get this shell running, cd into the src directory and type
- X"buildzsh". I tested it on the following machines, where it compiled
- Xjust by running this script:
- X
- XSun SPARCServer 4/690 running SunOS 4.1.2
- XNeXTstation running Mach 2.0
- XDECStation-5000 running ULTRIX 4.2
- XIris 4D/20 running IRIX 4.0.1
- XHP 9000/834 running HP-UX 7.00
- XIBM RS6000 running AIX 3.2
- X(rumored to work on a Pyramid)
- X
- XIn general, the more BSD-like your system, the more likely it will work.
- X
- XTabstops are 3 spaces. If you're going to look at my code, run it
- Xthough "expand -3" first, or set your tab stops to the same as mine.
- X
- XThere is a zsh mailing list, "zsh-list@cs.uow.edu.au". To have yourself
- Xadded to the list, send a request to "zsh-request@cs.uow.edu.au".
- X
- XThe author can be reached via email to one of the following addresses:
- X"pfalstad@phoenix.princeton.edu", "pfalstad@cs.ucsd.edu", "pf@ttisms.com",
- X"pf@gnu.ai.mit.edu".
- X
- XThanks to the following people for help, ideas, accounts, comments,
- Xpatches, etc.:
- X
- XCharles Hannum
- XDavid Dobkin
- XJim Mattson
- XCarlos Carvalho
- XBart Schaefer
- XPeter Gray
- XPure Software, Inc.
- XChris P. Ross
- XGary Oberbrunner
- XJonathan Hardwick
- XJohn Navarra
- XMichael Lamoureux
- XRick Lyons
- XDuncan Sinclair
- XMark R. Rubin
- XJohn Guthrie
- XJames Bonfield
- XChris Moore
- XThomas Winder
- XDavid J. MacKenzie
- XCharles Rendleman
- XRichard Ohnemus
- XNik Gervae
- XGottfried Necker
- XGoran Larsson
- XPaul E. Maisano
- XNorbert Kiesel
- XJosh Diamond
- XBill Miskovetz
- XPeter Moore
- XGeoff Wing
- XKent Dickey
- XJean-Jacques Moreau
- XMichael Brown
- XBruce Anderson
- XStephen Dum
- XLars E. Thon
- XMichael Brennan
- XXev Gittler
- XJarkko Hietaniemi
- XZbigniew J Tyrlik
- XPierre Racz
- XRick Ohnemus
- XRichard Dean
- XGary D. Kline
- XRobert A. Fabian
- XByron Rakitzis
- XDan Bernstein
- XJonathan Kamens
- XVincent Granet
- XDavid Wilson
- XGreg Noel
- XPaul Lew
- XDan Esbensen
- XKartik Subbarao
- XRoss Bunker
- XMichael Marucheck
- XChristopher Pirazzi
- XSteve Giovanetti
- XKennedy Lemke
- XEmin Gun Sirer
- XKazuo Itoh
- Xlots of other people, I'm sure
- X
- XModification history:
- X
- X2.2.0-2.1.0:
- Xo should be faster in general
- Xo fewer compilation warnings
- Xo SPROMPT now uses %R instead of %s for the incorrect string
- Xo no longer tries to create FIFOs on NeXTs (thereby causing a panic)
- Xo now gets usernames from NIS on irises without crashing (SGI's getpwnam()
- X called my strdup(), the pricks. Took me forever to find that. :-) )
- Xo fewer 7-bit assumptions
- Xo which/whence/type have new options:
- X -a = all (find all occurences of command in path)
- X -c = csh-style which (default for "which" command)
- Xo error message for cd str1 str2 is fixed
- Xo relative paths (including .) in cdpath now work
- Xo exclusion patterns in glob: ls *.c~lex.c prints all .c files but lex.c
- Xo bug with command substitution in chpwd fixed (buffers flushed twice)
- Xo relative paths in $path now work
- Xo "kill -9 -FOO" no longer kills shell
- Xo new options to history/fc:
- X -d = prints date commands were entered
- X -D = prints running time of commands
- Xo "history <num>" prints all commands SINCE <num> as well
- Xo history stored differently - should be more efficient
- Xo bg'ing a suspended zsh no longer causes problems
- Xo "set" no longer prints ONLY exported params (duh)
- Xo functions +t now allowed
- Xo redirection is done AFTER filename generation
- Xo print changes:
- X o print -u# prints to fd #
- X o print -p prints to coproc
- X o -D and -P perform \ substitution first
- X o print -0 changed to print -N
- Xo read changes:
- X o read -u# reads from fd #
- X o read -p reads from coproc
- X o read -z waits for input if nothing on buffer stack
- X o no longer reads from fd 0 if shell is getting input from there
- X o echo -n foo | read x now works
- Xo getopts is now POSIX conformant
- Xo compctl builtin added, replacing hostcmds, foocmds, etc. Controls
- X completion of various commands in zle.
- X format: compctl -options cmdnams ...
- X options tell where to get possible matches from, and include:
- X -c = command names
- X -f = filenames
- X -h = hostnames ($hosts)
- X -o = options
- X -v = vars
- X -b = bindings
- X -k name = elements of $name array
- X Any number of these options may be used together.
- X In addition, compctl -C -options will set the default completion
- X names when in command position (by default -c), and compctl -D -options
- X will set the default completion names used after unrecognized commands
- X or after redirections (by default -f).
- Xo foo && bar || fuu now works
- Xo ttyctl builtin added
- X ttyctl -f freezes the tty. no changes made to the tty settings by
- X external programs will be honored when this command is in effect.
- X ttyctl -u unfreezes the tty.
- X typically, "ttyctl -f" would be used in a zlogin or zshrc script after
- X "stty" has been called to set up the terminal.
- Xo [[ -e file ]] is now equivalent to [[ -a file ]]
- Xo [[ -h file ]] is now equivalent to [[ -L file ]]
- Xo the path is now hashed incrementally.
- X o if the HASHCMDS option is unset, path hashing is not done at all.
- X o if the HASHCMDS option is set but HASHDIRS is unset, commands are placed
- X in the hash table when first executed.
- X o if the HASHCMDS and HASHDIRS options are both set, commands are placed
- X in the hash table when first executed, along with all commands in
- X the directory that command was found in (and all directories earlier
- X in the path). This is the default situation.
- Xo "for i (*.c) do /bin/echo $i ; done | more" no longer hangs
- Xo coprocesses now work properly
- Xo READNULLCMD is now used instead of NULLCMD for "< file"
- Xo POSTEDIT is printed whenever the editor exits
- Xo rm path/path/* is now reported by checkrmall()
- Xo cmd >&- works
- Xo cmd >>! file works
- Xo time cmd no longer forks an extra process
- Xo setopt printexitvalue ; echo `false` no longer prints anything
- Xo here documents work inside eval, etc.
- Xo $(...) works inside here documents
- Xo "time" by itself prints the shell timings
- Xo locals in precmd() or chpwd() work
- Xo new glob qualifiers
- X o pat(M) sets markdirs, pat(^M) unsets it
- X o pat(N) sets nullglob, ...
- X o pat(D) sets globdots, ...
- Xo ls * only sorts numeric filenames specially if NUMERICGLOBSORT is set
- Xo setopt braceccl lets "echo {a-zA-Z}" work
- Xo new options: pushdignoredups nohistbeep overstrike
- Xo ls **/file is now equivalent to ls ****/file
- Xo !'s in history are now escaped when you return to them
- Xo history substitution is not done in script files
- Xo echo $(!-2) works
- Xo histverify and correct 'e' no longer put the edit line in the history
- Xo the :x, :q, and :gs modifiers work properly now
- Xo zsh -c 'ls =(ls)' no longer hangs
- Xo VSWTCH is now set to ^Z on the irises
- Xo zsh & no longer causes havoc
- Xo USERNAME and LOGNAME are kept separate
- Xo $manpath has been added for easy access to the $MANPATH components
- Xo zsh now realizes if it is running under emacs, and resigns itself to
- X the fact rather than panicking
- Xo SIGQUIT is ignored in the PRODUCTION version of zsh, and kills the shell
- X in the DEBUG version, rather than vice versa.
- Xo GLOBALZSHENV has been added, and GLOBALZPROFILE is sourced in the
- X proper place
- Xo "kill %" no longer causes the prompt to be printed 3 times if notify
- X is set on a NeXT
- Xo REPORTTIME has been added; if a job runs longer than this many seconds,
- X timing statistics are reported
- Xo timing statistics now include a job name (%J)
- Xo no longer talks about SIGHUPed jobs if the kill failed
- Xo no longer talks about running jobs which don't exist if you do eval exit
- X or if you have notify unset
- Xo foo=bar comman[tab], for/select/foreach i (*.c[tab] both work
- Xo [base]num inside $[...] works
- Xo foo=pat(n|ern) works
- Xo cd - prints the new directory
- Xo l[tab] works if l is an alias
- Xo select foo ; ... works (in $argv is assumed)
- Xo select reads from the right input
- Xo math identifiers can now contain numbers and _'s.
- Xo lots of serious memory heap trashing and leaks fixed
- Xo echo $HOME[*] no longer crashes the shell
- Xo SIGWINCH now changes LINES and COLUMNS in the environment
- Xo typeset +r TTY; TTY=foo no longer causes problems
- Xo ~ substitution is no longer done in FIGNORE
- Xo assignment to SECONDS works
- Xo "else if" is no longer a synonym for "elif" <thud>
- Xo lots of problems with null lists in flow constructs fixed
- Xo no correction done for >file
- Xo echo ${foo%bar is no longer weird
- Xo modifying array substitutions works
- Xo ^O can be bound to something
- Xo command substitution in signal handlers no longer causes problems
- Xo spelling correction is better ($PAHT is corrected), and SPROMPT
- X allows all the regular PROMPT escapes
- Xo new prompt escape sequence: %D{...} formats ... part using strftime
- Xo shell input no longer butchered using IFS
- Xo vi cmd mode has 's' bound to visubstitute, as it should be
- Xo you can use ^XS and ^XR in i-search mode
- Xo bindings to ^Z and ^@ work now on the irises
- Xo ^V{^S,^Q,^Z,etc} now works on sgttyb victims
- Xo nopromptclobber changed to nopromptcr
- Xo vi 'u' undo works a little better (?)
- Xo ESC-key bindings aren't screwed up if VISUAL is set to vi
- Xo newline in prompt now works reliably
- Xo vi change and delete work with forward-word/search, etc.
- Xo somewhat suboptimal screen refresh on irises fixed (several seconds
- X per character inserted when TERM=xterm??)
- Xo select list printing slightly different
- Xo magic-space's handling of hatchars "fixed"
- X
- X0.03-1.0:
- X - "..../" is now "****/". I know this isn't backward compatible,
- X but I had no choice; the string "..../" was unquotable.
- X - parser was rewritten and improved
- X - completion was improved, several bugs fixed (including
- X the "$([tab]" bug)
- X - vi mode editing is improved
- X - the value of PWD and OLDPWD in the environment now change
- X - the PROMPT formatting strings %W and %D now print the month
- X correctly
- X - >&2 echo "error message" no longer prints "bad file number"
- X - ${foo%pat} no longer alters the value of foo
- X - $_ works
- X - ALL_EXPORT no longer causes let statements to crash the shell
- X - continue works
- X - echo $MAIL no longer dumps core if MAIL is null
- X - the new tty driver is selected by default
- X - the s modifier no longer complains if it can't find the string
- X to substitute
- X - list-choices no longer fignores files
- X - cd is now smarter about symlinks
- X - negative subscripts other than -1 now work
- X - $(<filename) works better if filename contains $, ~, or =
- X - rehash no longer wastes memory
- X - with name=value assignments, name is checked to see if it is
- X a valid identifier
- X - !1; !2 no longer eats the semicolon
- X - $foo:h never returns the empty string if foo starts with /
- X - select crashed with some compilers
- X - problems with aliases in <(...) constructs have been fixed
- X - links pointing to nowhere are denoted with an '&' in listtypes
- X - negative arguments are supported
- X - the shell does not screw around with the tty so much
- X - lots of other stuff
- X
- X0.02-0.03:
- X - two stupid bugs that were introduced in the last patch were fixed:
- X - multiple command substitution on a line failed
- X - a file descriptor leak caused the shell to crash after a while
- X - added 'An Introduction to the Z Shell'
- X - behaves properly when the tty session dies suddenly
- X - had a serious memory leak on some systems
- X - the test and [ builtins have been added, although [[...]]
- X is more efficient
- X - in your prompt, %m2 now prints foo.bar, %m3 prints foo.bar.com, etc.
- X - the -D and -P options to print have been added
- X - the NULLCMD and ZDOTDIR parameters have been added
- X - ${*:-foo} works
- X - "$@" and "$arr[@]" work like ksh
- X - .zprofile is sourced before .zshrc in login shells
- X - the CSHJUNKIEQUOTES and PUSHDMINUS options have been added
- X - REAL_TTY compilation switch added
- X - aliases beginning with a space cause the history line to be junked
- X if HISTIGNORESPACE is set
- X - echo prints bad options instead of complaining about them
- X - "set -o" no longer dumps core
- X - "alias a=alias; date >a" no longer creates a file called "alias"
- X - "function foo() \n { date }" is now legal (the () and the newline
- X are allowed)
- X - nested brace expressions work properly
- X - disabled commands stay disabled after a rehash (or after the shell
- X finishes sourcing your .zshrc)
- X - corrected aliases work
- X - executables in the currect directory are now completed
- X - in "case foo", "foo" is not interpreted as a directory name with autocd
- X - aliases were not always interpreted properly after a completion
- X - bindkey '^?' didn't work
- X - echo ${HOST:-{bar}} didn't work
- X - editor update is more efficient in some cases
- X - menucomplete works even better
- X - assign to an array element "foo[1]=bar" didn't always work
- X - doesn't print directories like "~tmp" if HOME=/
- X - quotes in case statement patterns caused problems
- X - pressing ^C right after typing "fc" caused the editor to share
- X the tty with the shell
- X - echo $(echo 2) produced no output, but echo $(echo x) worked fine (weird)
- X
- X0.01-0.02:
- X - added script to convert most csh aliases to zsh aliases or functions
- X - fc -l (history) now appears in the history itself; HISTNOSTORE
- X option added to get old behavior
- X - the POSIX process group race has been fixed; so 'w | more' should
- X no longer hang
- X - FCEDIT added, to match the documentation
- X - %{...%} in the prompt added
- X - execute-named-cmd and execute-last-named-cmd bindings added
- X - sources ~/.zshenv in all shells, even if not interactive, unless
- X -f is given
- X - ^ and # are no longer `magic' by default; use EXTENDEDGLOB option
- X to use them
- X - now checks for tty sanity before each command
- X - if the right side of a variable assignment expands to more than
- X one word, array assignment is assumed; so foo=*.c now works
- X - ~foo is no longer expanded in completion
- X - select now works even if the argument list is not sorted
- X - menucompletebeep option added
- X - emacs mode is now 8-bit clean by default; use bindkey -em
- X to get your meta key back
- X - fc -R, fc -W added
- X - nocorrect added
- X - lines from history file are now split into words at spaces
- X - glob-complete, accept-and-menu-complete,
- X beginning-of-line-hist, end-of-line-hist bindings added
- X - insert-last-word bound to M-. in emacs mode by default; now moves
- X back through the history if run repeatedly
- X - J and K now bound to history search in vi mode
- X - delete-char no longer core dumps on an empty line
- X - menu-complete works better
- X - the editor checks the settings of VISUAL and EDITOR to set
- X default bindings
- X - using [[ ... ]] expressions on a symbolic link works as expected
- X - various problems with globbing were fixed
- X - xx is now the same as !! if HISTCHARS=x
- X - added config.h entry for compilers that don't know about void *
- X - lexical analysis made more efficient
- X - "if echo $? ; then : ; fi" no longer always prints 0
- X - removed all enums, '\x7f's from code
- X - in "case foo in bar) xxx ;; esac", foo and bar are no longer subject
- X to command alias expansion
- X - works on platforms where toupper('A') != 'A'
- X - \e sequence added to echo
- X - + options now work with set
- X - AUTORESUME and AUTOCD work better
- X - getopts works better (?)
- X - spell checking works better
- X - "let 2+3=" no longer crashes the shell
- X - "foo=bar; echo ${=foo}" no longer crashes the shell
- X - "zsh -c" or "zsh -o" no longer causes a core dump
- X - "unset MAIL; echo $MAIL" no longer causes a core dump
- X - "(xterm&xterm&)&" no longer causes a core dump
- X - "echo $HOM[tab]" beeps instead of deleting "$HOM"
- X - incremental history search works better
- X - the pwd of a fg'd job is now printed _before_ resuming it
- X - rv=`echo -n foo` no longer puts garbage in $rv
- X - "=1/*" now works as expected
- X - ^Z can now be bound to something
- X - the STTY parameter and the builtin builtin are now documented
- X - IFS=x; foo=`echo foo` no longer puts a newline in $foo
- X - $status added for csh compatibility
- X - arrays are automatically expanded if you say 'foo[1234]=x'
- X - shell now ignores SIGQUIT (it was commented out before :-)
- X - the times builtin works on systems where times() returns > 0
- X - no longer hangs the terminal if you ^S before flow control
- X is turned off
- X - "date ; read foo" now works in interactive shells
- X - <<-foo is now parsed as <<- foo, not << -foo
- X - fixed various errors in the documentation
- X
- X0.00-0.01:
- X - %M and %m now work as documented.
- X - bad things no longer happen if COLUMNS is set to 0
- X - SH_WORD_SPLIT and ${=foo} now work
- X - the default value of WORDCHARS includes more characters
- X - if the cursor is at the end of the line, vi-cmd-mode
- X moves it back one position.
- X - delete-char now acts more like x in vi.
- X - a "prompt" parameter has been added, which is equivalent to
- X PROMPT and PS1.
- X - zsh no longer expands symbolic links. The CHASELINKS option
- X has been provided to get the old behavior.
- X - history searches ignore lines that are the same as the line
- X in the buffer.
- X - you can get a literal ! in your prompt now with \!.
- X - -z, -n, and != in [[ ... ]] expressions work.
- X - the shell no longer hangs when inputting "[[ ]\n"
- X - the "menu-complete" and "menu-expand-or-complete" bindings have
- X been added.
- X - menu-complete no longer beeps.
- X - reverse-menu-complete no longer dumps core if it gets called before
- X a normal completion.
- X - typeahead lines are no longer thrown away on machines with sgttyb.
- X - !foo no longer matches lines with 'foo' in them (not at the beginning)
- X - kill -9 % no longer kills the shell
- X - no longer sources .zshrc from shell scripts or with -c
- X - no longer needs limits.h, strtol
- X - exporting HOSTTYPE, etc. works
- X - fixed serious bugs related to . in path
- X - numbers in weird bases now work
- X
- XKnown Bugs
- X - terminal acts weird under OpenWindows cmdtool
- X - xterm run in background inherits bad terminal modes
- X
- SHAR_EOF
- chmod 0644 zsh2.2/README ||
- echo 'restore of zsh2.2/README failed'
- Wc_c="`wc -c < 'zsh2.2/README'`"
- test 17490 -eq "$Wc_c" ||
- echo 'zsh2.2/README: original size 17490, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= zsh2.2/doc/intro.txt ==============
- if test ! -d 'zsh2.2/doc'; then
- echo 'x - creating directory zsh2.2/doc'
- mkdir 'zsh2.2/doc'
- fi
- if test -f 'zsh2.2/doc/intro.txt' -a X"$1" != X"-c"; then
- echo 'x - skipping zsh2.2/doc/intro.txt (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting zsh2.2/doc/intro.txt (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/doc/intro.txt' &&
- X
- X
- X
- X
- X
- X
- X An Introduction to the Z Shell
- X
- X
- X Paul Falstad
- X pfalstad@phoenix.princeton.edu
- X
- X
- X
- X
- X
- X
- Xzsh is a shell designed for interactive use, although it is
- Xalso a powerful scripting language. Many of the useful
- Xfeatures of bash, ksh, and tcsh were incorporated into zsh;
- Xmany original features were added. This document details
- Xsome of the unique features of zsh. It assumes basic
- Xknowledge of the standard UNIX shells; the intent is to show
- Xa reader already familiar with one of the other major shells
- Xwhat makes zsh more useful or more powerful. This document
- Xis not at all comprehensive; read the manual entry for a
- Xdescription of the shell that is complete and concise,
- Xalthough somewhat overwhelming and devoid of examples.
- X
- XFilename Generation
- X
- XOtherwise known as globbing, filename generation is quite
- Xextensive in zsh. Of course, it has all the basics:
- X
- X% ls
- XMakefile file.pro foo.o main.o q.c run234 stuff
- Xbar.o foo link morestuff run123 run240 sub
- Xfile.h foo.c main.h pipe run2 run303
- X% ls *.c
- Xfoo.c q.c
- X% ls *.[co]
- Xbar.o foo.c foo.o main.o q.c
- X% ls foo.?
- Xfoo.c foo.o
- X% ls *.[^c]
- Xbar.o file.h foo.o main.h main.o
- X% ls *.[^oh]
- Xfoo.c q.c
- X
- X
- XAlso, if the EXTENDEDGLOB option is set, some new features
- Xare activated. For example, the ^ character negates the
- Xpattern following it:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 2 -
- X
- X% setopt extendedglob
- X% ls -d ^*.c
- XMakefile file.pro link morestuff run2 run303
- Xbar.o foo main.h pipe run234 stuff
- Xfile.h foo.o main.o run123 run240 sub
- X% ls -d ^*.*
- XMakefile link pipe run2 run240 stuff
- Xfoo morestuff run123 run234 run303 sub
- X% ls -d ^Makefile
- Xbar.o foo link morestuff run123 run240 sub
- Xfile.h foo.c main.h pipe run2 run303
- Xfile.pro foo.o main.o q.c run234 stuff
- X% ls -d *.^c
- X.rhosts bar.o file.h file.pro foo.o main.h main.o
- X
- X
- XAn expression of the form <x-y> matches a range of integers:
- X
- X% ls run<200-300>
- Xrun234 run240
- X% ls run<300-400>
- Xrun303
- X% ls run<-200>
- Xrun123 run2
- X% ls run<300->
- Xrun303
- X% ls run<>
- Xrun123 run2 run234 run240 run303
- X
- X
- XGrouping is possible:
- X
- X% ls (foo|bar).*
- Xbar.o foo.c foo.o
- X% ls *.(c|o|pro)
- Xbar.o file.pro foo.c foo.o main.o q.c
- X
- X
- XAlso, the string ****/ forces a recursive search of sub-
- Xdirectories:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 3 -
- X
- X% ls -R
- XMakefile file.pro foo.o main.o q.c run234 stuff
- Xbar.o foo link morestuff run123 run240 sub
- Xfile.h foo.c main.h pipe run2 run303
- X
- Xmorestuff:
- X
- Xstuff:
- Xfile xxx yyy
- X
- Xstuff/xxx:
- Xfoobar
- X
- Xstuff/yyy:
- Xfrobar
- X% ls ****/*bar
- Xstuff/xxx/foobar stuff/yyy/frobar
- X% ls ****/f*
- Xfile.h foo foo.o stuff/xxx/foobar
- Xfile.pro foo.c stuff/file stuff/yyy/frobar
- X% ls *bar*
- Xbar.o
- X% ls ****/*bar*
- Xbar.o stuff/xxx/foobar stuff/yyy/frobar
- X% ls stuff/****/*bar*
- Xstuff/xxx/foobar stuff/yyy/frobar
- X
- X
- X
- XIt is possible to exclude certain files from the patterns
- Xusing the ~ character. A pattern of the form *.c~bar.c
- Xlists all files matching *.c, except for the file bar.c.
- X
- X% ls *.c
- Xfoo.c foob.c bar.c
- X% ls *.c~bar.c
- Xfoo.c foob.c
- X% ls *.c~f*
- Xbar.c
- X
- X
- X
- XOne can add a number of qualifiers to the end of any of
- Xthese patterns, to restrict matches to certain file types.
- XA qualified pattern is of the form
- X
- X pattern(...)
- X
- X
- Xwith single-letter qualifiers inside the parentheses.
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 4 -
- X
- X% alias l='ls -dF'
- X% l *
- XMakefile foo* main.h q.c run240
- Xbar.o foo.c main.o run123 run303
- Xfile.h foo.o morestuff/ run2 stuff/
- Xfile.pro link@ pipe run234 sub
- X% l *(/)
- Xmorestuff/ stuff/
- X% l *(@)
- Xlink@
- X% l *(*)
- Xfoo* link@ morestuff/ stuff/
- X% l *(x)
- Xfoo* link@ morestuff/ stuff/
- X% l *(X)
- Xfoo* link@ morestuff/ stuff/
- X% l *(R)
- Xbar.o foo* link@ morestuff/ run123 run240
- Xfile.h foo.c main.h pipe run2 run303
- Xfile.pro foo.o main.o q.c run234 stuff/
- X
- X
- XNote that *(x) and *(*) both match executables. *(X)
- Xmatches files executable by others, as opposed to *(x),
- Xwhich matches files executable by the owner. *(R) and *(r)
- Xmatch readable files; *(W) and *(w), which checks for writ-
- Xable files. *(W) is especially important, since it checks
- Xfor world-writable files:
- X
- X% l *(w)
- Xbar.o foo* link@ morestuff/ run123 run240
- Xfile.h foo.c main.h pipe run2 run303
- Xfile.pro foo.o main.o q.c run234 stuff/
- X% l *(W)
- Xlink@ run240
- X% l -l link run240
- Xlrwxrwxrwx 1 pfalstad 10 May 23 18:12 link -> /bin/false*
- X-rw-rw-rw- 1 pfalstad 0 May 23 18:12 run240
- X
- X
- XYou can filter out the symbolic links with the ^ character:
- X
- X% l *(W^@)
- Xrun240
- X% l *(x)
- Xfoo* link@ morestuff/ stuff/
- X% l *(x^@/)
- Xfoo*
- X
- X
- XTo find all plain files, you can use .:
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 5 -
- X
- X% l *(.)
- XMakefile file.h foo* foo.o main.o run123 run234 run303
- Xbar.o file.pro foo.c main.h q.c run2 run240 sub
- X% l *(^.)
- Xlink@ morestuff/ pipe stuff/
- X% l s*(.)
- Xstuff/ sub
- X% l *(p)
- Xpipe
- X% l -l *(p)
- Xprw-r--r-- 1 pfalstad 0 May 23 18:12 pipe
- X
- X
- X*(U) matches all files owned by you. To search for all
- Xfiles not owned by you, use *(^U):
- X
- X% l -l *(^U)
- X-rw------- 1 subbarao 29 May 23 18:13 sub
- X
- X
- XThis searches for setuid files:
- X
- X% l -l *(s)
- X-rwsr-xr-x 1 pfalstad 16 May 23 18:12 foo*
- X
- X
- XThis checks for a certain user's files:
- X
- X% ypmatch subbarao passwd
- Xsubbarao:*:3338:35:Kartik Subbarao:/u/subbarao:/usr/princeton/bin/zsh
- X% l -l *(u3338)
- X-rw------- 1 subbarao 29 May 23 18:13 sub
- X
- X
- X
- XStartup Files
- X
- XThere are five startup files that zsh will read commands
- Xfrom:
- X
- X$ZDOTDIR/.zshenv
- X$ZDOTDIR/.zprofile
- X$ZDOTDIR/.zshrc
- X$ZDOTDIR/.zlogin
- X$ZDOTDIR/.zlogout
- X
- X
- XIf ZDOTDIR is not set, then the value of HOME is used; this
- Xis the usual case.
- X
- X.zshenv is sourced on all invocations of the shell, unless
- Xthe -f option is set. It should contain commands to set the
- Xcommand search path, plus other important environment vari-
- Xables. .zshenv should not contain commands that produce
- Xoutput or assume the shell is attached to a tty.
- X
- X.zshrc is sourced in interactive shells. It should contain
- Xcommands to set up aliases, functions, options, key bind-
- Xings, etc.
- X
- X
- X
- X
- X
- X - 6 -
- X.zlogin is sourced in login shells. It should contain com-
- Xmands that should be executed only in login shells. .zlo-
- Xgout is sourced when login shells exit. .zprofile is simi-
- Xlar to .zlogin, except that it is sourced before .zshrc.
- X.zprofile is meant as an alternative to .zlogin for ksh
- Xfans; the two are not intended to be used together, although
- Xthis could certainly be done if desired. .zlogin is not the
- Xplace for alias definitions, options, environment variable
- Xsettings, etc.; as a general rule, it should not change the
- Xshell environment at all. Rather, it should be used to set
- Xthe terminal type and run a series of external commands
- X(fortune, msgs, etc).
- X
- XShell Functions
- X
- Xzsh also allows you to create your own commands by defining
- Xshell functions. For example:
- X
- X% yp () {
- X> ypmatch $1 passwd.byname
- X> }
- X% yp pfalstad
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- X
- X
- XThis function looks up a user in the NIS password map. The
- X$1 expands to the first argument to yp. The function could
- Xhave been equivalently defined in one of the following ways:
- X
- X% function yp {
- X> ypmatch $1 passwd.byname
- X> }
- X% function yp () {
- X> ypmatch $1 passwd.byname
- X> }
- X% function yp () ypmatch $1 passwd.byname
- X
- X
- XNote that aliases are expanded when the function definition
- Xis parsed, not when the function is executed. For example:
- X
- X% alias ypmatch=echo
- X% yp pfalstad
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- X
- X
- XSince the alias was defined after the function was parsed,
- Xit has no effect on the function's execution. However, if
- Xwe define the function again with the alias in place:
- X
- X% function yp () { ypmatch $1 passwd.byname }
- X% yp pfalstad
- Xpfalstad passwd.byname
- X
- X
- Xit is parsed with the new alias definition in place. There-
- Xfore, in general you must define aliases before functions.
- X
- XWe can make the function take multiple arguments:
- X
- X
- X
- X
- X
- X
- X - 7 -
- X
- X% unalias ypmatch
- X% yp () {
- X> for i
- X> do ypmatch $i passwd.byname
- X> done
- X> }
- X% yp pfalstad subbarao sukthnkr
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- Xsubbarao:*:3338:35:Kartik Subbarao:/u/subbarao:/usr/princeton/bin/zsh
- Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
- X
- X
- XThe for i loops through each of the function's arguments,
- Xsetting i equal to each of them in turn. We can also make
- Xthe function do something sensible if no arguments are
- Xgiven:
- X
- X% yp () {
- X> if (( $# == 0 ))
- X> then echo usage: yp name ...; fi
- X> for i; do ypmatch $i passwd.byname; done
- X> }
- X% yp
- Xusage: yp name ...
- X% yp pfalstad sukthnkr
- Xpfalstad:*:3564:35:Paul John Falstad:/u/pfalstad:/usr/princeton/bin/zsh
- Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
- X
- X
- X$# is the number of arguments supplied to the function. If
- Xit is equal to zero, we print a usage message; otherwise, we
- Xloop through the arguments, and ypmatch all of them.
- X
- XHere's a function that selects a random line from a file:
- X
- X% randline () {
- X> integer z=$(wc -l <$1)
- X> sed -n $[RANDOM % z + 1]p $1
- X> }
- X% randline /etc/motd
- XPHOENIX WILL BE DOWN briefly Friday morning, 5/24/91 from 8 AM to
- X% randline /etc/motd
- XSunOS Release 4.1.1 (PHOENIX) #19: Tue May 14 19:03:15 EDT 1991
- X% randline /etc/motd
- X| Please use the "msgs" command to read announcements. Refer to the |
- X% echo $z
- X
- X%
- X
- X
- Xrandline has a local variable, z, that holds the number of
- Xlines in the file. $[RANDOM % z + 1] expands to a random
- Xnumber between 1 and z. An expression of the form $[...]
- Xexpands to the value of the arithmetic expression within the
- Xbrackets, and the RANDOM variable returns a random number
- Xeach time it is referenced. % is the modulus operator, as
- Xin C. Therefore, sed -n $[RANDOM%z+1]p picks a random line
- Xfrom its input, from 1 to z.
- X
- X
- X
- X
- X
- X
- X - 8 -
- XFunction definitions can be viewed with the functions buil-
- Xtin:
- X
- X% functions randline
- Xrandline () {
- X integer z=$(wc -l <$1)
- X sed -n $[RANDOM % z + 1]p $1
- X
- X}
- X% functions
- Xyp () {
- X if let $# == 0
- X
- X then
- X echo usage: yp name ...
- X
- X fi
- X for i
- X do
- X ypmatch $i passwd.byname
- X
- X done
- X
- X}
- Xrandline () {
- X integer z=$(wc -l <$1)
- X sed -n $[RANDOM % z + 1]p $1
- X
- X}
- X
- X
- XHere's another one:
- X
- X% cx () { chmod +x $* }
- X% ls -l foo bar
- X-rw-r--r-- 1 pfalstad 29 May 24 04:38 bar
- X-rw-r--r-- 1 pfalstad 29 May 24 04:38 foo
- X% cx foo bar
- X% ls -l foo bar
- X-rwxr-xr-x 1 pfalstad 29 May 24 04:38 bar
- X-rwxr-xr-x 1 pfalstad 29 May 24 04:38 foo
- X
- X
- XNote that this could also have been implemented as an alias:
- X
- X% chmod 644 foo bar
- X% alias cx='chmod +x'
- X% cx foo bar
- X% ls -l foo bar
- X-rwxr-xr-x 1 pfalstad 29 May 24 04:38 bar
- X-rwxr-xr-x 1 pfalstad 29 May 24 04:38 foo
- X
- X
- X
- XInstead of defining a lot of functions in your .zshrc, all
- Xof which you may not use, it is often better to use the
- Xautoload builtin. The idea is, you create a directory where
- Xfunction definitions are stored, declare the names in your
- X.zshrc, and tell the shell where to look for them. Whenever
- Xyou reference a function, the shell will automatically load
- X
- X
- X
- X
- X
- X - 9 -
- Xit into memory.
- X
- X% mkdir /tmp/funs
- X% cat >/tmp/funs/yp
- Xypmatch $1 passwd.byname
- X^D
- X% cat >/tmp/funs/cx
- Xchmod +x $*
- X^D
- X% FPATH=/tmp/funs
- X% autoload cx yp
- X% functions cx yp
- Xundefined cx ()
- Xundefined yp ()
- X% chmod 755 /tmp/funs/{cx,yp}
- X% yp egsirer
- Xegsirer:*:3214:35:Emin Gun Sirer:/u/egsirer:/bin/sh
- X% functions yp
- Xyp () {
- X ypmatch $1 passwd.byname
- X}
- X
- X
- XThis idea has other benefits. By adding a #! header to the
- Xfiles, you can make them double as shell scripts. (Although
- Xit is faster to use them as functions, since a separate pro-
- Xcess is not created.)
- X
- X% ed /tmp/funs/yp
- X25
- Xi
- X#! /usr/local/bin/zsh
- Xw
- X42
- Xq
- X% </tmp/funs/yp
- X#! /usr/local/bin/zsh
- Xypmatch $1 passwd.byname
- X% /tmp/funs/yp sukthnkr
- Xsukthnkr:*:1267:35:Rahul Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
- X
- X
- XNow other people, who may not use zsh, or who don't want to
- Xcopy all of your .zshrc, may use these functions as shell
- Xscripts.
- X
- XDirectories
- X
- XOne nice feature of zsh is the way it prints directories.
- XFor example, if we set the prompt like this:
- X
- Xphoenix% PROMPT='%~> '
- X~> cd src
- X~/src>
- X
- X
- Xthe shell will print the current directory in the prompt,
- Xusing the ~ character. However, zsh is smarter than most
- Xother shells in this respect:
- X
- X
- X
- X
- X
- X
- X - 10 -
- X
- X~/src> cd ~subbarao
- X~subbarao> cd ~maruchck
- X~maruchck> cd lib
- X~maruchck/lib> cd fun
- X~maruchck/lib/fun> foo=/usr/princeton/common/src
- X~maruchck/lib/fun> cd ~foo
- X~foo> cd ..
- X/usr/princeton/common> cd src
- X~foo> cd news/nntp
- X~foo/news/nntp> cd inews
- X~foo/news/nntp/inews>
- X
- X
- XNote that zsh prints other users' directories in the form
- X~user. Also note that you can set a parameter and use it as
- Xa directory name; zsh will act as if foo is a user with the
- Xlogin directory /usr/princeton/common/src. This is con-
- Xvenient, especially if you're sick of seeing prompts like
- Xthis:
- X
- Xphoenix:/usr/princeton/common/src/X.V11R4/contrib/clients/xv/docs>
- X
- X
- XIf you get stuck in this position, you can give the current
- Xdirectory a short name, like this:
- X
- X/usr/princeton/common/src/news/nntp/inews> inews=$PWD
- X/usr/princeton/common/src/news/nntp/inews> echo ~inews
- X/usr/princeton/common/src/news/nntp/inews
- X~inews>
- X
- X
- XWhen you reference a directory in the form ~inews, the shell
- Xassumes that you want the directory displayed in this form;
- Xthus simply typing echo ~inews or cd ~inews causes the
- Xprompt to be shortened. You can define a shell function for
- Xthis purpose:
- X
- X~inews> namedir () { $1=$PWD ; : ~$1 }
- X~inews> cd /usr/princeton/bin
- X/usr/princeton/bin> namedir pbin
- X~pbin> cd /var/spool/mail
- X/var/spool/mail> namedir spool
- X~spool> cd .msgs
- X~spool/.msgs>
- X
- X
- XYou may want to add this one-line function to your .zshrc.
- X
- Xzsh can also put the current directory in your title bar, if
- Xyou are using a windowing system. One way to do this is
- Xwith the chpwd function, which is automatically executed by
- Xthe shell whenever you change directory. If you are using
- Xxterm, this will work:
- X
- Xchpwd () { print -Pn '^[]2;%~^G' }
- X
- X
- XThe -P option tells print to treat its arguments like a
- X
- X
- X
- X
- X
- X - 11 -
- Xprompt string; otherwise the %~ would not be expanded. The
- X-n option suppresses the terminating newline, as with echo.
- X
- XIf you are using an IRIS wsh, do this:
- X
- Xchpwd () { print -Pn '^[P1.y%~^[' }
- X
- X
- XThe print -D command has other uses. For example, to print
- Xthe current directory to standard output in short form, you
- Xcan do this:
- X
- X% print -D $PWD
- X~subbarao/src
- X
- X
- Xand to print each component of the path in short form:
- X
- X% print -D $path
- X/bin /usr/bin ~locbin ~locbin/X11 ~/bin
- X
- X
- X
- XDirectory Stacks
- X
- XIf you use csh, you may know about directory stacks. The
- Xpushd command puts the current directory on the stack, and
- Xchanges to a new directory; the popd command pops a direc-
- Xtory off the stack and changes to it.
- X
- Xphoenix% cd
- Xphoenix% PROMPT='Z %~> '
- XZ ~> pushd /tmp
- X/tmp ~
- XZ /tmp> pushd /usr/etc
- X/usr/etc /tmp ~
- XZ /usr/etc> pushd /usr/bin
- X/usr/bin /usr/etc /tmp ~
- XZ /usr/bin> popd
- X/usr/etc /tmp ~
- XZ /usr/etc> popd
- X/tmp ~
- XZ /tmp> pushd /etc
- X/etc /tmp ~
- XZ /etc> popd
- X/tmp ~
- X
- X
- Xzsh's directory stack commands work similarly. One differ-
- Xence is the way pushd is handled if no arguments are given.
- XAs in csh, this exchanges the top two elements of the direc-
- Xtory stack:
- X
- XZ /tmp> dirs
- X/tmp ~
- XZ /tmp> pushd
- X~ /tmp
- X
- X
- Xunless the stack only has one entry:
- X
- X
- X
- X
- X
- X - 12 -
- X
- XZ ~> popd
- X/tmp
- XZ /tmp> dirs
- X/tmp
- XZ /tmp> pushd
- X~ /tmp
- X
- X
- Xor unless the PUSHDTOHOME option is set:
- X
- XZ ~> setopt pushdtohome
- XZ ~> pushd
- X~ ~ /tmp
- X
- X
- X
- XAs an alternative to using directory stacks in this manner,
- Xwe can get something like a directory history by setting a
- Xfew more options and parameters:
- X
- X~> DIRSTACKSIZE=8
- X~> setopt autopushd pushdminus pushdsilent pushdtohome
- X~> alias dh='dirs -v'
- X~> cd /tmp
- X/tmp> cd /usr
- X/usr> cd bin
- X/usr/bin> cd ../pub
- X/usr/pub> dh
- X0 /usr/pub
- X1 /usr/bin
- X2 /usr
- X3 /tmp
- X4 ~
- X/usr/pub> cd -3
- X/tmp> dh
- X0 /tmp
- X1 /usr/pub
- X2 /usr/bin
- X3 /usr
- X4 ~
- X/tmp> ls =2/df
- X/usr/bin/df
- X/tmp> cd -4
- X~>
- X
- X
- XNote that =2 expanded to the second directory in the history
- Xlist, and that cd -3 recalled the third directory in the
- Xlist.
- X
- XYou may be wondering what all those options do. AUTOPUSHD
- Xmade cd act like pushd. (alias cd=pushd is not sufficient,
- Xfor various reasons.) PUSHDMINUS swapped the meaning of cd
- X+1 and cd -1; we want them to mean the opposite of what they
- Xmean in csh, because it makes more sense in this scheme, and
- Xit's easier to type:
- X
- X
- X
- X
- X
- X
- X
- X
- X - 13 -
- X
- X~> dh
- X0 ~
- X1 /tmp
- X2 /usr/pub
- X3 /usr/bin
- X4 /usr
- X~> unsetopt pushdminus
- X~> cd +1
- X/tmp> dh
- X0 /tmp
- X1 ~
- X2 /usr/pub
- X3 /usr/bin
- X4 /usr
- X/tmp> cd +2
- X/usr/pub>
- X
- X
- XPUSHDSILENT keeps the shell from printing the directory
- Xstack each time we do a cd, and PUSHDTOHOME we mentioned
- Xearlier:
- X
- X/usr/pub> unsetopt pushdsilent
- X/usr/pub> cd /etc
- X/etc /usr/pub /tmp ~ /usr/bin /usr
- X/etc> cd
- X~ /etc /usr/pub /tmp ~ /usr/bin /usr
- X~> unsetopt pushdtohome
- X~> cd
- X/etc ~ /usr/pub /tmp ~ /usr/bin /usr
- X/etc>
- X
- X
- XDIRSTACKSIZE keeps the directory stack from getting too
- Xlarge, much like HISTSIZE:
- X
- X/etc> setopt pushdsilent
- X/etc> cd /
- X/> cd /
- X/> cd /
- X/> cd /
- X/> cd /
- X/> cd /
- X/> cd /
- X/> cd /
- X/> dh
- X0 /
- X1 /
- X2 /
- X3 /
- X4 /
- X5 /
- X6 /
- X7 /
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X
- X - 14 -
- XCommand/Process Substitution
- X
- XCommand substitution in zsh can take two forms. In the
- Xtraditional form, a command enclosed in backquotes (`...`)
- Xis replaced on the command line with its output. This is
- Xthe form used by the older shells. Newer shells (like zsh)
- Xalso provide another form, $(...). This form is much easier
- Xto nest.
- X
- X% ls -l `echo /vmunix`
- X-rwxr-xr-x 1 root 1209702 May 14 19:04 /vmunix
- X% ls -l $(echo /vmunix)
- X-rwxr-xr-x 1 root 1209702 May 14 19:04 /vmunix
- X% who | grep mad
- Xsubbarao ttyt7 May 23 15:02 (mad55sx15.Prince)
- Xpfalstad ttyu1 May 23 16:25 (mad55sx14.Prince)
- Xsubbarao ttyu6 May 23 15:04 (mad55sx15.Prince)
- Xpfalstad ttyv3 May 23 16:25 (mad55sx14.Prince)
- X% who | grep mad | awk '{print $2}'
- Xttyt7
- Xttyu1
- Xttyu6
- Xttyv3
- X% cd /dev; ls -l $(who |
- X> grep $(echo mad) |
- X> awk '{ print $2 }')
- Xcrwx-w---- 1 subbarao 20, 71 May 23 18:35 ttyt7
- Xcrw--w---- 1 pfalstad 20, 81 May 23 18:42 ttyu1
- Xcrwx-w---- 1 subbarao 20, 86 May 23 18:38 ttyu6
- Xcrw--w---- 1 pfalstad 20, 99 May 23 18:41 ttyv3
- X
- X
- XMany common uses of command substitution, however, are
- Xsuperseded by other mechanisms of zsh:
- X
- X% ls -l `tty`
- Xcrw-rw-rw- 1 root 20, 28 May 23 18:35 /dev/ttyqc
- X% ls -l $TTY
- Xcrw-rw-rw- 1 root 20, 28 May 23 18:35 /dev/ttyqc
- X% ls -l `which rn`
- X-rwxr-xr-x 1 root 172032 Mar 6 18:40 /usr/princeton/bin/rn
- X% ls -l =rn
- X-rwxr-xr-x 1 root 172032 Mar 6 18:40 /usr/princeton/bin/rn
- X
- X
- XA command name with a = prepended is replaced with its full
- Xpathname. This can be very convenient. If it's not con-
- Xvenient for you, you can turn it off:
- X
- X% ls
- X=foo =bar
- X% ls =foo =bar
- Xzsh: foo not found
- X% setopt noequals
- X% ls =foo =bar
- X=foo =bar
- X
- X
- X
- XAnother nice feature is process substitution:
- X
- X
- X
- X
- X
- X - 15 -
- X
- X% who | fgrep -f =(print -l root lemke shgchan subbarao)
- Xroot console May 19 10:41
- Xlemke ttyq0 May 22 10:05 (narnia:0.0)
- Xlemke ttyr7 May 22 10:05 (narnia:0.0)
- Xlemke ttyrd May 22 10:05 (narnia:0.0)
- Xshgchan ttys1 May 23 16:52 (gaudi.Princeton.)
- Xsubbarao ttyt7 May 23 15:02 (mad55sx15.Prince)
- Xsubbarao ttyu6 May 23 15:04 (mad55sx15.Prince)
- Xshgchan ttyvb May 23 16:51 (gaudi.Princeton.)
- X
- X
- XA command of the form =(...) is replaced with the name of a
- Xfile containing its output. (A command substitution, on the
- SHAR_EOF
- true || echo 'restore of zsh2.2/doc/intro.txt failed'
- fi
- echo 'End of zsh2.2 part 1'
- echo 'File zsh2.2/doc/intro.txt is continued in part 2'
- echo 2 > _shar_seq_.tmp
- exit 0
-
- exit 0 # Just in case...
-